function Comms( ply, saywhat )
	if( string.find(string.lower(saywhat), ":") )then
		local message = ply:GetName()..": "..string.sub(saywhat,string.find(saywhat, ":")+1)
		if( string.find(string.lower(saywhat), "t:") == 1 )then
			TeamRadio(ply,message)
		elseif( string.find(string.lower(saywhat), "s:") == 1 )then
			Say(ply,message)
		elseif( string.find(string.lower(saywhat), "team:") == 1 )then
			TeamSet(ply,saywhat)
		end
	end
end
hook.Add ( "PlayerSay", "playerSaid", Comms ) 

function TeamRadio(ply,msg)
	for k, player in pairs(player.GetAll())do
		if(player:Team()==ply:Team())then
			player:ChatPrint( msg )
		end
	end
end

function Say(ply,msg)
	local ents = ents.FindInSphere( ply:GetPos(), 900 )
	for k, ent in pairs(ents)do
		if(ent:IsPlayer())then
			--ent:PrintMessage (HUD_PRINTTALK, msg )
			ent:ChatPrint( msg )
		end
	end
end

function TeamSet(ply,msg)
	local val = tonumber(string.sub(msg,6,6))
	local ok = true
	local old = ply:Team()
	if(val != nil)then
		ply:SetTeam(val)
	end
	val = tonumber(string.sub(msg,7,7))
	if(val != nil)then
		ply:SetTeam(val)
	end
	if(ply:Team()== TEAM_CONNECTING)then
		ply:ChatPrint(HUD_PRINTTALK, "Invalid, use 'team: #' where # is 1-4")
		ok = false
		ply:SetTeam(old)
	end
	if(ok)then
	local note = ply:GetName().." is now a "..team.GetName(ply:Team())
		for k, v in pairs(player.GetAll())do
			if(!(v:UserID() == ply:UserID()))then
				v:ChatPrint(note)
			end
		end
		ply:ChatPrint("You are now a "..team.GetName(ply:Team()))
	end
end
